package com.ruoyi.teaching.listener;

import com.ruoyi.teaching.domain.YaHighInterview;
import com.ruoyi.teaching.index.Interview;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author coach tam
 * @email 327395128@qq.com
 * @values 坚持灵活 灵活坚持
 * @since 2025/4/7
 */
@Component
@Slf4j
public class InterviewListener {

    @Autowired
    private ElasticsearchRestTemplate elasticsearchRestTemplate;


    @RabbitListener(bindings =
    @QueueBinding(
            value = @Queue(name = "queue.canal"),
            exchange = @Exchange(name = "exchange.fanout.canal", type = ExchangeTypes.TOPIC),
            key = {"example"}
    )
    )
    public void listenInterview(Map<String,Object> json){
        log.debug("消费者接收到面试题消息：【{}】",json);
        // YaHighInterview ->  Interview
//        Interview interview = new Interview();
//        interview.setId(record.getId());
//        interview.setQuestion(record.getQuestion());
//        interview.setAnswer(record.getAnswer());
//        interview.setKnowledgePoint(record.getKnowledgePoint());
//        interview.setImportance(record.getImportance());
//        interview.setStage(record.getStage());
//        elasticsearchRestTemplate.save(interview);
//        log.debug("消费者接收到面试题消息：【{}】",interview);
    }

/*    @RabbitListener(bindings =
        @QueueBinding(
                value = @Queue(name = "edusmart.interview.es"),
                exchange = @Exchange(name = "edusmart.interview.exchange", type = ExchangeTypes.TOPIC),
                key = {"interview.add","interview.update"}
        )
    )
    public void listenInterview(YaHighInterview record){
        // YaHighInterview ->  Interview
        Interview interview = new Interview();
        interview.setId(record.getId());
        interview.setQuestion(record.getQuestion());
        interview.setAnswer(record.getAnswer());
        interview.setKnowledgePoint(record.getKnowledgePoint());
        interview.setImportance(record.getImportance());
        interview.setStage(record.getStage());
        elasticsearchRestTemplate.save(interview);
        log.debug("消费者接收到面试题消息：【{}】",interview);
    }

    @RabbitListener(bindings =
    @QueueBinding(
            value = @Queue(name = "edusmart.interview.es"),
            exchange = @Exchange(name = "edusmart.interview.exchange", type = ExchangeTypes.TOPIC),
            key = "interview.delete"
    )
    )
    public void listenInterview(Long id){
        // YaHighInterview ->  Interview
        Interview interview = new Interview();
        interview.setId(id);
        elasticsearchRestTemplate.delete(interview);
    }*/



}
